package com.iflytek.ossp.auth.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.iflytek.ossp.auth.entity.MenuInfo;
import com.iflytek.ossp.auth.service.MenuService;

@Controller("menuController")
public class MenuController {

	@Resource
	private MenuService menuService;

	@RequestMapping("/menu")
	public String menu() {
		return "auth/menu/menu";
	}

	@RequestMapping("/menu/subMenus")
	@ResponseBody
	public List<MenuInfo> getSubMenus(Long parentId) {
		return menuService.getMenusByParent(parentId);
	}
	
	@RequestMapping("/menu/permitSubMenus")
	@ResponseBody
	public List<MenuInfo> permitSubMenus(Long parentId) {
		return menuService.getPermitMenusByParent(parentId);
	}
	
	@RequestMapping("/menu/delete")
	@ResponseBody
	public void deleteMenu(Long id) {
		menuService.deleteMenu(id);
	}

	@RequestMapping("/menu/save")
	@ResponseBody
	public MenuInfo saveMenu(MenuInfo menu) {
		menuService.saveMenu(menu);
		return menu;
	}

	@RequestMapping("/menu/move")
	@ResponseBody
	public void moveMenu(Long id, Long toId, Integer order) {
		menuService.moveMenu(id, toId, order);
	}

}
